﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DesignPattern
{
    // 饿汉模式
    class Danli1
    {
        private static readonly Danli1 instance = new Danli1();  // 类在加载时直接创建实例，线程安全

        private Danli1() { }    // 构造函数私有，防止外部调用创建实例

        public static Danli1 Instance
        {
            get
            {
                return instance;
            }
        }

        private int count = 0;

        public int Count
        {
            get
            {
                return count;
            }
        }
        public void IncreatCount()
        {
            Interlocked.Increment(ref count);
        }
    }
}
